// const axios=require('../lib/axios')

class Index{
    constructor(){

        this.init()
    }
    
    //获取 hot-goods  热销商品
    async init(){
        let hot= await axios.get('http://localhost:1998/all-goods?describe=hot-goods')
        let news = await axios.get('http://localhost:1998/all-goods?describe=new-goods')
        // console.log(hot); 返回对象
        this.createHot(hot.data)
        this.createNew(news.data)
        
    }
    //创建热销商品列表
    createHot(hot){
        // console.log(hot)
        let  ul=document.querySelector('.hotsale ul')
        let str=''
        hot.map(item=>{
            // console.log(item.img.showimg)
           str+=`<li class="well-item">
              <a href="http://localhost:4023/html/product.html?id=${item.id}" target="_blank">
               <div class="correct"><img src="${item.img.showimg}" alt=""></div>
               <p>${item.title}</p>
                <span>
                    <em>&#165 ${item.price}</em> <i>&#165 ${item.oldprice}</i>
                </span>
              </a>    
            </li>`
        })

        ul.innerHTML=str
    }

    //创建热销商品列表
    createNew(data){
        // console.log(data)
        let  ul=document.querySelector('.whatsnew ul')
        let str=''
        data.map(item=>{
            // console.log(1)
           str+=`<li class="well-item">
           <a href="http://localhost:4023/html/product.html?id=${item.id}" target="_blank">
           <div class="correct"><img src="${item.img.showimg}" alt=""></div>
           <p>${item.title}</p>
            <span>
                <em>&#165 ${item.price}</em> <i>&#165 ${item.oldprice}</i>
            </span>
          </a>  
            </li>`
        })

        ul.innerHTML=str
    }
}



new Index();
